package com.leo.springbootmultithreadbasic.lock.reentrantlock.basicdemo.demo1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Mock一个Service
 *
 *
 * @author Leo
 * @version V1.0
 * @date 2021/10/31 11:36 PM
 */
public class MyService {

    private static final Logger logger = LoggerFactory.getLogger(MyService.class);

    // create reentrantLock
    private Lock lock = new ReentrantLock();


    public void testLock() {
        // get lock
        lock.lock();

        for (int i = 0; i < 5; i++) {
            logger.info("ThreadName={}", Thread.currentThread().getName() + " " + i);
        }

        // release lock

        lock.unlock();
    }

}
